/*
 *  Copyright 2020-2025 the original author or authors.
 *  You cannot use this file unless authorized by the author.
 */

package org.ipig.web.security.impl;

import org.apache.commons.lang.StringUtils;
import org.ipig.web.security.AuthManager;

import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * DefaultAuthManager
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @version $$Id$$
 * @since 1.0
 */
public class DefaultAuthManager implements AuthManager {
    private static Map<String, String> tokenMap = new ConcurrentHashMap();

    static {
        tokenMap.put("ts", "X-Token对应服务器的详细信息");
    }


    public String createToken(String username) {
        String token = UUID.randomUUID().toString();
        tokenMap.put(token, username);
        return token;
    }


    public boolean checkToken(String token) {
        return (!StringUtils.isEmpty(token) && tokenMap.containsKey(token));
    }
}